<template>
  <div id="myactivity">
    <scroller class="pointstagli" scrollbar-y lock-x :scroll-bottom-offset="60" @on-scroll-bottom="onScrollBottom1" slot="slist1" ref="scrollerBottom1">
      <div class="activity-list">
        <ul>
          <li v-if="isShow1" v-for="item, id, type in data1" :id="id=item.id" :type="type = item.type" @click="routeToActivitydetails((name = item.activityTitle), type, id, (url = item.url))">
            <div class="pic">
              <img v-if="item.activityImg === undefined" src="../../assets/images/vote-pic.png">
              <img v-else-if="item.activityImg !== undefined" :src="item.activityImg">
            </div>
            <div class="right">
              <p><span class="title">{{item.activityTitle}}</span><span class="status">{{item.status}}</span></p>
            </div>
          </li>
          <li v-if="isShow2" v-for="item, id, type in data1" :id="id=item.id" :type="type = item.type" @click="routeToActivitydetails1((name = item.activityTitle), type, id, (url = item.url))">
            <div class="pic">
              <img v-if="item.activityImg === undefined" src="../../assets/images/vote-pic.png">
              <img v-else-if="item.activityImg !== undefined" :src="item.activityImg">
            </div>
            <div class="right">
              <p><span class="title">{{item.activityTitle}}</span><span class="status">{{item.status}}</span></p>
            </div>
          </li>
        </ul>
      </div>
       <load-more :value="false" :show-loading="isshowload" :tip="loadtip">Loading</load-more>
    </scroller>
  </div>
</template>
<script>
  import { Scroller, LoadMore } from 'vux'
  export default {
    name: 'myactivity',
    components: {
      Scroller,
      LoadMore
    },
    data () {
      return {
        data1: [],
        pageIndex: 0,
        isupload: false,
        isShow2: false,
        isShow1: false,
        isshowload: false,
        loadtip: '',
        bottomCount1: 0
      }
    },
    created () {
      this.getActivitylist()
      .then((data) => {
        // console.log(this.data1.push)
        this.data1.push.apply(this.data1, data)
        if (data.length > 0) {
          this.bottomCount1 = this.data1.length
        }
      }, () => {})
    },
    methods: {
      getActivitylist: function () {
        if (this.$route.query.type === '1') {
          this.isShow1 = true
          return this.$axios.post(this.apidomain + '/api/activity/getVoteAndApplyList/' + this.getCookie('appid'), {
            pageIndex: this.bottomCount1
          })
          .then((response) => {
            if (response.data.errorCode === '0') {
              return response.data.data
            } else {
              return []
            }
          })
          .catch((error) => {
            console.log(error)
            return []
          })
        } else if (this.$route.query.type === '2') {
          this.isShow2 = true
          return this.$axios.post(this.apidomain + '/api/activity/getExpireActivityList/' + this.getCookie('appid'), {
            pageIndex: this.bottomCount1
          })
          .then((response) => {
            if (response.data.errorCode === '0') {
              return response.data.data
            } else {
              return []
            }
          })
          .catch((error) => {
            console.log(error)
            return []
          })
        } else if (this.$route.query.type === '3') {
          return this.$axios.post(this.apidomain + '/api/activity/getNingActivityList/' + this.getCookie('appid'), {
            pageIndex: this.bottomCount1
          })
          .then((response) => {
            if (response.data.errorCode === '0') {
              return response.data.data
            } else {
              return []
            }
          })
          .catch((error) => {
            console.log(error)
            return []
          })
        }
      },
      onScrollBottom1 () {
        if (this.isupload) {
          this.isshowload = true
          this.loadtip = '加载中...'
        } else {
          this.isupload = true
          setTimeout(() => {
            this.$nextTick(() => {
              this.getActivitylist(this.bottomCount1)
              .then((data) => {
                this.data1.push.apply(this.data1, data)
                if (data.length > 0) {
                  this.bottomCount1 = this.data1.length
                }
              }, () => {})
              this.$refs.scrollerBottom1.reset()
              this.isshowload = false
              this.loadtip = ''
              this.isupload = false
            })
          }, 1000)
        }
      },
      routeToActivitydetails (name, type, id, url) {
        if (type === 1) {
          window.zhuge.track('Click', {
            '事件名称': '会员中心-会员活动-互动活动-点击',
            '访问时间': new Date().toLocaleString(),
            'OpenID': this.getCookie('openid'),
            '活动名称': name
          }, () => {
            this.routeto('activitydetails', { id: id })
          })
        }
        if (type === 2) {
          window.zhuge.track('Click', {
            '事件名称': '会员中心-会员活动-互动活动-点击',
            '访问时间': new Date().toLocaleString(),
            'OpenID': this.getCookie('openid'),
            '活动名称': name
          }, () => {
            this.routeto('vote', { id: id })
          })
        }
        if (type === 3) {
          window.zhuge.track('Click', {
            '事件名称': '会员中心-会员活动-宁聚日-点击',
            '访问时间': new Date().toLocaleString(),
            'OpenID': this.getCookie('openid'),
            '活动名称': name
          }, () => {
            window.location.href = url
          })
        }
      },
      routeToActivitydetails1 (name, type, id, url) {
        if (type === 1) {
          window.zhuge.track('Click', {
            '事件名称': '会员中心-会员活动-往期活动-点击',
            '访问时间': new Date().toLocaleString(),
            'OpenID': this.getCookie('openid'),
            '活动名称': name
          }, () => {
            this.routeto('activitydetails', { id: id })
          })
        }
        if (type === 2) {
          window.zhuge.track('Click', {
            '事件名称': '会员中心-会员活动-往期活动-点击',
            '访问时间': new Date().toLocaleString(),
            'OpenID': this.getCookie('openid'),
            '活动名称': name
          }, () => {
            this.routeto('vote', { id: id })
          })
        }
        if (type === 3) {
          window.zhuge.track('Click', {
            '事件名称': '会员中心-会员活动-宁聚日-点击',
            '访问时间': new Date().toLocaleString(),
            'OpenID': this.getCookie('openid'),
            '活动名称': name
          }, () => {
            window.location.href = url
          })
        }
      }
    }
  }
</script>
<style lang="less">
  @import "../../assets/less/myactivity/myactivity.less";
</style>
